﻿using System;
using System.Collections.Generic;
using System.Linq;
using Abp.Runtime.Session;
using pandx.Mulan.Books.Dto;
using pandx.Mulan.DataImExPorting.Excel;
using pandx.Mulan.Dto;
using pandx.Mulan.Storage;

namespace pandx.Mulan.Books.Exporting
{
    public class BookListExcelExporter:NpoiExcelExporterBase,IBookListExcelExporter
    {
        private readonly IAbpSession _abpSession;

        public BookListExcelExporter(IAbpSession abpSession, ITempFileCacheManager tempFileCacheManager) : base(
            tempFileCacheManager)
        {
            _abpSession = abpSession;
        }

        public FileDto ExportToExcel(List<BookListDto> bookListDtos)
        {
            return CreateExcelPackage("替换为导出名字_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss") + ".xlsx",
                excelPackage =>
                {
                    var sheet = excelPackage.CreateSheet("替换为导出名字");
                    AddHeader(sheet,
                        "","","","","","","","创建用户","创建用户"
                    );
                    AddObjects(sheet,2,bookListDtos,
                        _=>_.Id,_=>_.CreationTime,_=>_.CreatorUserId,_=>_.LastModificationTime,_=>_.LastModifierUserId,_=>_.Title,_=>_.BookType,_=>_.CreatorUserName,_=>_.CreatorName
                    );
                    for(var i=1;i<=bookListDtos.Count;i++)
                    {
                        sheet.AutoSizeColumn(i);
                    }
                });
        }
    }
}
